/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modules.enderecamento.models.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import modules.enderecamento.util.Funcoes;
import modules.enderecamento.util.HibernateUtil;
import org.hibernate.SessionFactory;

/**
 *
 * @author Clezio
 */
public class AbstractDAO {
    private SessionFactory sessionFactory;

     public AbstractDAO() throws Exception{
         sessionFactory = HibernateUtil.getSessionFactory();
     }

    /**
     * @return the sessionFactory
     */
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    /**
     * @param sessionFactory the sessionFactory to set
     */
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public static Connection obterConexao() throws Exception{
        Connection conn = null;
        try {
            Class.forName(HibernateUtil.getCfg().getProperty("hibernate.connection.driver_class"));
            conn = DriverManager.getConnection(
                    HibernateUtil.getCfg().getProperty("hibernate.connection.url"),
                    HibernateUtil.getCfg().getProperty("hibernate.connection.username"),
                    HibernateUtil.getCfg().getProperty("hibernate.connection.password")
                    );
        } catch (Exception ex) {
            Funcoes.registrarLog(ex);
        }
        return conn;
    }
}
